package Behavior;

import AOP.Printer;
import Agents.AActuator;
import Agents.Messageable;
import Messages.AMessage;

import jade.core.AID;
import jade.core.Agent;
import jade.core.behaviours.TickerBehaviour;
import jade.lang.acl.ACLMessage;

public class EmitBehavior extends TickerBehaviour
{

	public EmitBehavior(AActuator a, long period) 
	{
		super((Agent)a, period);
	}

	protected void onTick() 
	{
		((AActuator) myAgent).calculateNewValue();
		if(((AActuator)myAgent).value > 0)
		{
			Printer.Print(myAgent.getLocalName(), ((AActuator)myAgent).value, ((AActuator)myAgent).setpoint, ((AActuator)myAgent).currentpoint);
			ACLMessage message = new ACLMessage( ACLMessage.INFORM );
			message.setContent(AMessage.constructMessage((Messageable)myAgent, AMessage.MessageType.EMIT));
		
			//System.out.println("Floor Heater " + myAgent.getLocalName() + ": Emitting " + ((AActuator)myAgent).unit.name() + ":" + ((AActuator)myAgent).value);
		
			AMessage.broadcastToAll((Messageable)myAgent, message);
		}
	}

}
